<?php

/*
 * 2021/7/15
 * 14:22
 * User: 2650332702@qq.com
 */

namespace App\Api\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Seckill extends Model
{
    use HasFactory;
    protected $table='cmc_store_seckill';

    static public function DataSorting($allow_field,$page,$where)
    {
        $current_time = time();

        return Seckill::orderBy($where,'desc')
            ->when($where=='start_time' ,function ($query) use ($where,$current_time){
                $query->where('start_time','<',$current_time);
            })
            ->select($allow_field)
            ->when($page,function ($query) use ($page){
                $query->paginate($page);
            })
            ->paginate($page)
            ->toArray();
    }
    //根据秒杀ID单个字段
    static public function skInGood($skid,$where)
    {
        return Seckill::where('id',$skid)->get([$where])->toArray()[0][$where];
    }

}
